package com.ats.controller;

import java.io.IOException;
import java.io.PrintWriter;
import java.text.SimpleDateFormat;
import java.util.Date;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.ats.model.User;
import com.ats.service.JobRecordSerivce_xh;
import com.ats.service.StudentService_xh;
import com.ats.serviceimpl.JobRecordSerivceImpl_xh;
import com.ats.serviceimpl.StudentServiceImpl_xh;

import net.sf.json.JSONArray;
/**
 * 提交作业
 * @author xh
 *
 */
public class CompleteController_xh extends HttpServlet{
	JobRecordSerivce_xh jrs = new JobRecordSerivceImpl_xh();
	StudentService_xh stus =new StudentServiceImpl_xh();
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		// TODO Auto-generated method stub
	doPost(req, resp);
	}
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
	// TODO Auto-generated method stub
		resp.setCharacterEncoding("utf8");
		PrintWriter  pw = resp.getWriter();
		int jrid=Integer.parseInt(req.getParameter("jrid"));
		int uid =Integer.parseInt(req.getParameter("uid"));
		//查询学生ID 根据用户id
		int sid =stus.findSidByUid(uid);
		String answer =req.getParameter("answer");
		//获取当前时间
		SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		Date now = new Date();
		String myDate=df.format(now);
		//提价作业
		boolean flag =jrs.updateJobRecordBySid(myDate,sid,jrid,answer);
		pw.write(flag+"");
		pw.flush();
		pw.close();	

		

	}

}
